package game.creator;

import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import game.DataStore;
import game.gameobject.misc.Crate;
import game.gameobject.misc.Rope;
import game.gameobject.misc.Torch;

public abstract class SpatialCreator {

    public static Geometry createBlock(Vector3f halfExtents, Vector3f location, float mass) {
        Box blockShape = new Box(halfExtents.getX(), halfExtents.getY(), halfExtents.getZ());
        Geometry block = new Geometry("block", blockShape);
	Material blockMat = new Material(DataStore.assetManager, "Common/MatDefs/Light/Lighting.j3md");
	blockMat.setBoolean("UseMaterialColors",true);
	blockMat.setColor("Diffuse",  ColorRGBA.White);
        blockMat.setColor("Specular", ColorRGBA.White);
        block.setMaterial(blockMat);
	block.setLocalTranslation(location);
	DataStore.physicsHubNode.attachChild(block);
        RigidBodyControl blockControl = new RigidBodyControl(mass);
        block.addControl(blockControl);
	DataStore.bulletAppState.getPhysicsSpace().add(block);
        return block;
    }

    public static Rope createRope(Vector3f startPoint, Vector3f endPoint, float lengthOrSlack) {
        Material ropeMat = new Material(DataStore.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        ropeMat.setColor("Color", ColorRGBA.Red);
	Rope rope;
	if (endPoint == null)
	    rope = new Rope(startPoint, lengthOrSlack, 0.075f, ropeMat);
	else
	    rope = new Rope(startPoint, endPoint, lengthOrSlack, 0.075f, ropeMat);
        DataStore.physicsHubNode.attachChild(rope);
        DataStore.bulletAppState.getPhysicsSpace().addAll(rope);
        return rope;
    }

    public static Torch createTorch(Vector3f location) {
	Torch torchy = new Torch();
	torchy.setLocalTranslation(location);
	DataStore.physicsHubNode.attachChild(torchy);
	torchy.createPhysicsControl();
	DataStore.bulletAppState.getPhysicsSpace().add(torchy);
	return torchy;
    }

    public static Crate createCrate(Vector3f location) {
	Crate crate = new Crate();
	crate.setLocalTranslation(location);
	crate.setShadowMode(ShadowMode.CastAndReceive);
	DataStore.physicsHubNode.attachChild(crate);
	crate.createPhysicsControl();
	DataStore.bulletAppState.getPhysicsSpace().add(crate);
	return crate;
    }
}
